package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SeckillVoucherDTO;
import com.sky.entity.SeckillVoucher;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * @Author: invictusQAQ
 * @Date: 2023-09-06-17:17
 * @Description:
 */
@Mapper
public interface VoucherMapper {

    /**
     * 新增秒杀券
     * @param seckillVoucher
     * @return void
     **/
    @Insert("insert into seckill_voucher(id, title, sub_title, rules, pay_value, actual_value, type, status, " +
            "create_time, update_time, create_user, update_user, stock, begin_time, end_time) values " +
            "(#{id},#{title},#{subTitle},#{rules},#{payValue},#{actualValue},#{type}," +
            "#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{stock},#{beginTime},#{endTime})")
    @AutoFill(OperationType.INSERT)
    void addSeckillVoucher(SeckillVoucher seckillVoucher);

    /**
     * 秒杀券分页查询
     * @param seckillVoucherDTO
     * @return Page<SeckillVoucher>
     **/
    Page<SeckillVoucher> pageQuery(SeckillVoucherDTO seckillVoucherDTO);

    /**
     * 扣减秒杀券
     * @return Integer
     **/
    @Update("update seckill_voucher set stock = stock-1 where stock > 0 and id =#{voucherId}")
    Integer decrSeckillVoucher(Long voucherId);
}
